<!-- <template>
    <div>
        <h1>登录界面</h1>
        <table class="table table-bordered">
            <tr>
                <td>用户名</td>
                <td><input type="text" v-model="info.UL_Name" placeholder="请输入用户名"/></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" v-model="info.UL_Pwd" placeholder="请输入密码"/></td>
            </tr>
            <tr>
                <td colspan="2"><input value="登录" type="button" @click="Login"/></td>
            </tr>
        </table>
    </div>
</template>
<script setup lang="ts">
import { ref } from 'vue';

const info=ref({
    UL_Name:'',
    UL_Pwd:''
})
import axios from 'axios';
import { useRouter } from 'vue-router';
import { useUserStore } from '../../store/index';
const userStore=useUserStore();
const route=useRouter();
alert(userStore.id)


const Login = () => {
    if(info.value.UL_Name=='' || info.value.UL_Pwd==''){
        alert("用户名或密码不能为空")
        return;
    }



    alert(info.value.UL_Name+"," +info.value.UL_Pwd)

    axios({
        method: 'get',
        url: 'http://localhost:57969/api/User/UserLogin',
        params:{
            Uname:info.value.UL_Name,
            Upwd:info.value.UL_Pwd,
        }
    })
    .then(function (res) {
        console.log(res.data);
        if(res.data.RM_Id==1)
        {
            //验证用户名不存在
            alert(res.data.RM_Msg)
            
        }
        else if(res.data.RM_Id==2)
        {
            //验证账号密码不匹配
            alert(res.data.RM_Msg)
        }
        else
        {
            alert(res.data.RM_Msg)
            //通过路由将用户编号传递到用户详情类

            SearchUid(res.data.RM_Data[0].U_Id);
            route.push({
                name:'Details',
                params:{
                    id:res.data.RM_Data[0].U_Id,
                }
            })
            
        }


    })

    .catch(function (error) {
        console.log(error);
    })



}
const SearchUid =(Uid:any)=>{
    axios({
        method: 'get',
        url: 'http://localhost:57969/api/User/SearchUid',
        params:{
            id:Uid,
        }
    })

    .then(function (res) {
        if(res.data>0) 
        {
            alert("即将跳转到主页面");
            route.push({
                name:'InvestShowUser',
                params:{
                    id:Uid,
                }
            })
        }     
        else
        {
            route.push({
                name:'Details',
                params:{
                    id:Uid,
                }
            })
        }  
    })

    .catch(function (error) {
        console.log(error);
    })
}
</script> -->





<template>
    <div class="pure-g content">
        <div class="pure-form pure-u-1">
            <h4>请登录您的账号</h4>
            <fieldset class="pure-group">
                <input type="text" class="pure-input-1" placeholder="用户名" v-model="info.UL_Name">
                <input type="password" class="pure-input-1" placeholder="密　码" v-model="info.UL_Pwd">
            </fieldset>
            <button class="pure-button pure-u-1 pure-button-primary" @click="Login()">登　录</button>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const info=ref({
    UL_Name:'',
    UL_Pwd:''
})
import axios from 'axios';
import { useRouter } from 'vue-router';
import { useUserStore } from '../../store/index';
const userStore=useUserStore();
const route=useRouter();
alert(userStore.id)


const Login = () => {
    if(info.value.UL_Name=='' || info.value.UL_Pwd==''){
        alert("用户名或密码不能为空")
        return;
    }



    alert(info.value.UL_Name+"," +info.value.UL_Pwd)

    axios({
        method: 'get',
        url: 'http://localhost:57969/api/User/UserLogin',
        params:{
            Uname:info.value.UL_Name,
            Upwd:info.value.UL_Pwd,
        }
    })
    .then(function (res) {
        console.log(res.data);
        if(res.data.RM_Id==1)
        {
            //验证用户名不存在
            alert(res.data.RM_Msg)
            
        }
        else if(res.data.RM_Id==2)
        {
            //验证账号密码不匹配
            alert(res.data.RM_Msg)
        }
        else
        {
            alert(res.data.RM_Msg)
            //通过路由将用户编号传递到用户详情类

            SearchUid(res.data.RM_Data[0].U_Id);
            route.push({
                name:'Details',
                params:{
                    id:res.data.RM_Data[0].U_Id,
                }
            })
            
        }


    })

    .catch(function (error) {
        console.log(error);
    })



}
const SearchUid =(Uid:any)=>{
    axios({
        method: 'get',
        url: 'http://localhost:57969/api/User/SearchUid',
        params:{
            id:Uid,
        }
    })

    .then(function (res) {
        if(res.data>0) 
        {
            alert("即将跳转到主页面");
            route.push({
                name:'InvestShowUser',
                params:{
                    id:Uid,
                }
            })
        }     
        else
        {
            route.push({
                name:'Details',
                params:{
                    id:Uid,
                }
            })
        }  
    })

    .catch(function (error) {
        console.log(error);
    })
}
</script>

